#include <endian.h>	// defines byte-order

#include "l3tol.h"

/**
 * Convert 3-byte disk addresses to arry of longs.
 * 	(from big-endian architecture to local)
 *
 *	lp = array  of longs, the destination
 *	cp = array  of bytes, the source
 *	nd = number of daddrs to convert
 */
void	l3tol( long lp[], byte cp[] , int nd )
{
	byte * a = (byte *) lp;
	byte * b = (byte *) cp;

	for (int i = 0 ; i < nd ; i++) {
#ifndef	__BYTE_ORDER
# error	Oops, byte order of this machine is unknown
#else
# if	__BYTE_ORDER == __LITTLE_ENDIAN
	    /* big-endian => little-endian (intel) */
	    a[3] = 0;
	    a[2] = b[0];	// least
	    a[1] = b[1];
	    a[0] = b[2];	// most
	    a += 4;
	    b += 3;
# else
	/* big-endian => big-endian */
	    *a++ = 0;
	    *a++ = *b++;	// least
	    *a++ = *b++;
	    *a++ = *b++;	// most
# endif
#endif
	}
}
